package com.wk.springframework.support;

import com.wk.springframework.config.BeanDefinition;
import com.wk.springframework.config.BeanFactory;

import java.util.Objects;

/**
 * 定义好模板,具体的由子类实现
 */
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {
    @Override
    public Object getBean(String beanName) {
        Object singleton = getSingleton(beanName);
        if (Objects.nonNull(singleton)) return singleton;
        BeanDefinition beanDefinition = getBeanDefinition(beanName);
        return createBean(beanName, beanDefinition);
    }

    protected abstract BeanDefinition getBeanDefinition(String beanName);

    protected abstract Object createBean(String beanName, BeanDefinition beanDefinition);

}
